﻿using B.S.DataBase.MyProject.Domain.Infrastructures;
using B.S.DataBase.MyProject.Domain.wdx.ViewModels;
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyProject.Infrastructure;
using MediatR;
using MedicalPCTerminal.Read.API.Appcation.Commands.Sign;

namespace MedicalPCTerminal.Read.API.Appcation.CommandHandlers.Sign
{
    public class GetTeamSlectCommandHandler : IRequestHandler<GetTeamSlectCommand, APIResult<List<View_TeamSlect>>>
    {
        private readonly SqlSugarContext sqlSugar;

        public GetTeamSlectCommandHandler(SqlSugarContext sqlSugar)
        {
            this.sqlSugar = sqlSugar;
        }

        public Task<APIResult<List<View_TeamSlect>>> Handle(GetTeamSlectCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<View_TeamSlect>> result = new APIResult<List<View_TeamSlect>>();
            var list = sqlSugar.db.Queryable<TeamInfo>()
                .Select(x => new View_TeamSlect
                {
                    TeamID = x.TeamID,
                    TeamName = x.TeamName,
                });
            result.data = list.ToList();
            result.Code = APIEnum.查询成功;
            result.Msg = APIEnum.查询成功.ToString();
            return Task.FromResult(result);
        }
    }
}
